import { createRouter, createWebHistory } from "vue-router";
const routes = [
    {
        path: "/",
        redirect: "/main/home"
    },
    {
        path: "/login",
        name: "login",
        component: () => import("@/pages/login/login.vue")
    },
    {
        path: "/main/home",
        name: "home",
        component: () => import("@/pages/home/home.vue")
    },
    {
        path: "/main",
        name: "main",
        component: () => import("@/pages/main.vue"),
        children: [
            //工单管理-新增工单详情
            {
                path: "/main/reportManage/reportOrderDetail",
                name: "reportOrderDetail",
                component: () => import("@/pages/reportOrderDetail/reportOrderDetail.vue"),
                meta: {
                    name: "工单详情",
                    path: "/main/reportManage/reportOrderDetail",
                    parentPath: "/main/reportManage"
                }
            },
            //系统管理-设备管理-设备台账
            {
                path: "/main/equipmentManagement/equipmentLedger",
                name: "equipmentLedger",
                component: () => import("@/pages/equipmentManagement/equipmentLedger.vue"),
                meta: {
                    name: "设备台账",
                    path: "/main/equipmentManagement/equipmentLedger",
                    parentPath: "/main/equipmentManagement"
                }
            },
            //基础运维-计划管理-一级保养
            {
                path: "/main/planManagement/firstMaintain",
                name: "firstMaintain",
                component: () => import("@/pages/planManagement/firstMaintain.vue"),
                meta: {
                    name: "一级保养",
                    path: "/main/planManagement/firstMaintain",
                    parentPath: "/main/planManagement"
                }
            },
            //基础运维-计划管理-二级保养
            {
                path: "/main/planManagement/secondMaintain",
                name: "secondMaintain",
                component: () => import("@/pages/planManagement/secondMaintain.vue"),
                meta: {
                    name: "二级保养",
                    path: "/main/planManagement/secondMaintain",
                    parentPath: "/main/planManagement"
                }
            },
            //基础运维-设备管理-设计资料
            {
                path: "/main/equipmentManagement/designInformation",
                name: "designInformation",
                component: () => import("@/pages/equipmentManagement/designInformation.vue"),
                meta: {
                    name: "设计资料",
                    path: "/main/equipmentManagement/designInformation",
                    parentPath: "/main/equipmentManagement"
                }
            },
            //基础运维-策略管理-检查项库
            {
                path: "/main/tacticalManagement/checkItemTemplateLibrary",
                name: "checkItemTemplateLibrary",
                component: () => import("@/pages/tacticalManagement/checkItemTemplateLibrary.vue"),
                meta: {
                    name: "检查项库",
                    path: "/main/tacticalManagement/checkItemTemplateLibrary",
                    parentPath: "/main/tacticalManagement"
                }
            },
            //基础运维-策略管理-检查项明细
            {
                path: "/main/tacticalManagement/checkItemDetails",
                name: "checkItemDetails",
                component: () => import("@/pages/tacticalManagement/checkItemDetails.vue"),
                meta: {
                    name: "检查项明细",
                    path: "/main/tacticalManagement/checkItemDetails",
                    parentPath: "/main/tacticalManagement"
                }
            },
            //基础运维-策略管理-策略模板
            {
                path: "/main/tacticalManagement/policyTemplate",
                name: "policyTemplate",
                component: () => import("@/pages/tacticalManagement/policyTemplate.vue"),
                meta: {
                    name: "策略模板",
                    path: "/main/tacticalManagement/policyTemplate",
                    parentPath: "/main/tacticalManagement"
                }
            },
            //基础运维-策略管理-策略模板-检查项
            {
                path: "/main/tacticalManagement/checkTheEntry",
                name: "checkTheEntry",
                component: () => import("@/pages/tacticalManagement/checkTheEntry.vue"),
                meta: {
                    name: "检查项",
                    path: "/main/tacticalManagement/checkTheEntry",
                    parentPath: "/main/tacticalManagement"
                }
            },
            //系统管理-角色管理-页面权限
            {
                path: "/main/roleManage/role",
                name: "role",
                component: () => import("@/pages/roleManage/role.vue"),
                meta: {
                    name: "页面权限",
                    path: "/main/roleManage/role",
                    parentPath: "/main/roleManage"
                }
            },
            //基础运维-维保管理-维保详情
            {
                path: "/main/maintenanceManage/maintenanceDetail",
                name: "maintenanceDetail",
                component: () => import("@/pages/maintenanceDetail/maintenanceDetail.vue"),
                meta: {
                    name: "维保详情",
                    path: "/main/maintenanceManage/maintenanceDetail",
                    parentPath: "/main/maintenanceManage"
                }
            },
            //基础运维-报修管理-拖期配置
            {
                path: "/main/reportManage/delay",
                name: "delay",
                component: () => import("@/pages/reportManage/delay.vue"),
                meta: {
                    name: "拖期配置",
                    path: "/main/reportManage/delay",
                    parentPath: "/main/reportManage"
                }
            }
        ]
    }
    // {
    //   path: "/:pathMatch(.*)",
    //   name: "404",
    //   component: () => import("@/pages/404/404.vue"),
    // },
];

const router = createRouter({
    routes,
    history: createWebHistory()
});

router.beforeEach((to, from) => {
    if (to.path !== "/login") {
        const token = localStorage.getItem("token");
        if (!token) {
            return "/login";
        }
    }
    if (to.path == "/main") {
        return "/main/home";
    }
});
export default router;
